<?php
/**
 * Created by PhpStorm.
 * User: caohejie
 * Date: 2018/8/17
 * Time: 10:46
 */

namespace Workerman\app;

use Workerman\Worker;

class UdpLog{

    /**
     * udp连接实例
     */
    public $udp_server;


    public function __construct()
    {

        $this->udp_server = new Worker("udp://0.0.0.0:2347");

        $this->udp_server->count = 4;

        $this->udp_server->onWorkerStart=array($this,'on_start');

        $this->udp_server->onMessage=array($this,'on_message');



    }

    public function on_start($worker){

        global $dosomeing;

        $db=new namespace\Connection('localhost', '3306', 'root', 'gaopeng', 'udp_log');

        $dosomeing=new \Workerman\app\dosomeing();

        $dosomeing->db=$db;
    }

    public function on_message($connection, $data){

        global $dosomeing;

        $dosomeing->connection=$connection;

        $data=json_decode($data,true);

        if($data){
            $dosomeing->{$data['fun']}($data);
        }

    }

    public function run(){

        Worker::runAll();

    }


}